/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model.entity;

import com.alibaba.fastjson.annotation.JSONField;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author dingnangen
 */
@Entity
@Table(name = "task")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Task.findAll", query = "SELECT t FROM Task t"),
    @NamedQuery(name = "Task.findByIdtask", query = "SELECT t FROM Task t WHERE t.idtask = :idtask"),
    @NamedQuery(name = "Task.findByTranCost", query = "SELECT t FROM Task t WHERE t.tranCost = :tranCost"),
    @NamedQuery(name = "Task.findByTimeCost", query = "SELECT t FROM Task t WHERE t.timeCost = :timeCost"),
    @NamedQuery(name = "Task.findByDispatchCost", query = "SELECT t FROM Task t WHERE t.dispatchCost = :dispatchCost"),
    @NamedQuery(name = "Task.findByBegintime", query = "SELECT t FROM Task t WHERE t.begintime = :begintime"),
    @NamedQuery(name = "Task.findByFinishtime", query = "SELECT t FROM Task t WHERE t.finishtime = :finishtime")})
public class Task implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idtask")
    private Integer idtask;
    @Basic(optional = false)
    @NotNull
    @Column(name = "tranCost")
    private double tranCost;
    @Basic(optional = false)
    @NotNull
    @Column(name = "timeCost")
    private double timeCost;
    @Basic(optional = false)
    @NotNull
    @Column(name = "dispatchCost")
    private double dispatchCost;
    @Lob
    @Size(max = 2147483647)
    @Column(name = "directionstring")
    private String directionstring;
    @JSONField (format="HH:mm:ss") 
    @Column(name = "begintime")
    @Temporal(TemporalType.TIME)
    private Date begintime;
    @Column(name = "finishtime")
    @Temporal(TemporalType.TIME)
    private Date finishtime;
    @OneToMany(mappedBy = "idtask")
    private List<TaskCustomerdemand> taskCustomerdemandList;
    @JoinColumn(name = "idattendance", referencedColumnName = "idattendance")
    @ManyToOne(optional = false)
    private Attendance idattendance;
    @JSONField(label = "extask")
    @JoinColumn(name = "idsolution", referencedColumnName = "idsolution")
    @ManyToOne(optional = false)
    private Solution idsolution;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idtask")
    private List<Tracehistory> tracehistoryList;
    @Transient
    private int realcap;

    public Task() {
    }

    public Task(Integer idtask) {
        this.idtask = idtask;
    }

    public Task(Integer idtask, double tranCost, double timeCost, double dispatchCost) {
        this.idtask = idtask;
        this.tranCost = tranCost;
        this.timeCost = timeCost;
        this.dispatchCost = dispatchCost;
    }

    public Integer getIdtask() {
        return idtask;
    }

    public void setIdtask(Integer idtask) {
        this.idtask = idtask;
    }

    public double getTranCost() {
        return tranCost;
    }

    public void setTranCost(double tranCost) {
        this.tranCost = tranCost;
    }

    public double getTimeCost() {
        return timeCost;
    }

    public void setTimeCost(double timeCost) {
        this.timeCost = timeCost;
    }

    public double getDispatchCost() {
        return dispatchCost;
    }

    public void setDispatchCost(double dispatchCost) {
        this.dispatchCost = dispatchCost;
    }

    public String getDirectionstring() {
        return directionstring;
    }

    public void setDirectionstring(String directionstring) {
        this.directionstring = directionstring;
    }

    public Date getBegintime() {
        return begintime;
    }

    public void setBegintime(Date begintime) {
        this.begintime = begintime;
    }

    public Date getFinishtime() {
        return finishtime;
    }

    public void setFinishtime(Date finishtime) {
        this.finishtime = finishtime;
    }

    @XmlTransient
    public List<TaskCustomerdemand> getTaskCustomerdemandList() {
        return taskCustomerdemandList;
    }

    public void setTaskCustomerdemandList(List<TaskCustomerdemand> taskCustomerdemandList) {
        this.taskCustomerdemandList = taskCustomerdemandList;
    }

    public Attendance getIdattendance() {
        return idattendance;
    }

    public void setIdattendance(Attendance idattendance) {
        this.idattendance = idattendance;
    }

    public Solution getIdsolution() {
        return idsolution;
    }

    public void setIdsolution(Solution idsolution) {
        this.idsolution = idsolution;
    }

    @XmlTransient
    public List<Tracehistory> getTracehistoryList() {
        return tracehistoryList;
    }

    public void setTracehistoryList(List<Tracehistory> tracehistoryList) {
        this.tracehistoryList = tracehistoryList;
    }

    public int getRealcap() {
        return realcap;
    }

    public void setRealcap(int realcap) {
        this.realcap = realcap;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idtask != null ? idtask.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Task)) {
            return false;
        }
        Task other = (Task) object;
        if ((this.idtask == null && other.idtask != null) || (this.idtask != null && !this.idtask.equals(other.idtask))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.entity.Task[ idtask=" + idtask + " ]";
    }

}
